﻿package top.college.cjh;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import model.AdminVO;
import model.DepartVO;
import model.StudentVO;

// 학생 조회
public class Admin_Stu_vedit  extends JPanel{

	private static Admin_Select as = new Admin_Select();
	private static StudentVO pass = new StudentVO();
	
	
	public Admin_Stu_vedit() {


		setLayout( new BorderLayout( 0, 0) );
		StuTop();
		JScrollPane chart = new JScrollPane();
		add( chart, BorderLayout.CENTER );
		
		
		
		
		final DefaultTableModel model = new DefaultTableModel(){
				@Override
				public boolean isCellEditable(int row, int column) {
		
					return false;
				}
			
		};
		
		
		
		String title[]= { "순 번", "학번(아이디)", "비밀번호", "이름", "연락처", "주소", "소속학과", "학점", "생성일" };
		model.setColumnIdentifiers( title );
		
		
		
		
		for ( StudentVO s : as.selectStu() ){
			String tr =	s.getStd_tr();
			String pw = s.getStd_pw();
			String no = s.getStd_no();
			String name = s.getStd_name();
			String tel = s.getStd_tel();
			String addr = s.getStd_addr();
			String dno = s.getDept_no();
			String tot = s.getTot_point();
			String date = s.getReg_date();
			
			model.addRow( new String[]{ tr, pw,  no, name, tel, addr, dno, tot, date });
			
		}
		  
		
		
		
		
		JTable stuTable = new JTable();
		stuTable.addMouseListener( new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				if ( e.getClickCount() == 2 ){
					JTable departTable = (JTable) e.getSource();
					int row = departTable.getSelectedRow();//선택행+
					pass.setStd_tr( (String) model.getValueAt(row, 0) ) ;
					pass.setStd_pw( (String) model.getValueAt(row, 1) ) ;
					pass.setStd_no( (String) model.getValueAt(row, 2) ) ;
					pass.setStd_name( (String) model.getValueAt(row, 3) ) ;
					pass.setStd_tel((String) model.getValueAt(row, 4) ) ;
					pass.setStd_addr ( (String) model.getValueAt(row, 5) ) ;
					pass.setDept_no( (String) model.getValueAt(row, 6) ) ;
					pass.setTot_point( (String) model.getValueAt(row, 7) ) ;
					pass.setReg_date( (String) model.getValueAt(row, 8) ) ;
					// int col = table.getSelectedColumn();		// 선택열
					// String val = (String) table.getValueAt(row, col);
					// String msg = row + "/" + col + "/" + val + "\n" + "더브루 클릭크";
					// String msg = row + ""; // + "/" + col + "/" + val + "\n" + "더브루 클릭크";
				
					 new Admin_Stu_Dial( pass );
					// 체크박스 트루펄스
					
				
				}
								
			//	super.mouseClicked(e);
			}
			
		});
		
		
		stuTable.setModel(model);
		
		
				
		chart.setViewportView(stuTable);
		
		setVisible( true );
		
		
	}
	
	
	private void StuTop(){
		
		JPanel top = new JPanel();
		
		JTextField serch = new JTextField();
		serch.setColumns( 30 );
		top.add( serch );	
		
		JButton see = new JButton();
		see.setText( "검 색" );
		
		JButton create = new JButton();
		create.setText( "추 가 등 록" );
		create.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		
			//	StudentVO v = new StudentVO();
				new Admin_Apend_Stu();
				
				
			}

		});
		
		top.add( see );		
		top.add( create );
		add(  top, BorderLayout.NORTH );
		
		
	} // adminTop
	
		
		
		
	
		
		
		
		
		
		
		
		
		
		
		
		
		
} // class
